package com.hxzy.module.auth.config.oauth;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hxzy.framework.common.resp.UserDto;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;

/**
 * @Author wy
 * @Description springsecurity输出登录用户的信息(授权和认证)
 * @Date 2024/1/25 16:17
 * @Version 1.0
 */
@Getter
@Setter
public class SecurityUser implements UserDetails, Serializable {
    /**
     * ID
     */
    private Long id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 用户密码
     */
    private String password;
    /**
     * 用户状态
     */
    private Boolean enabled;
    /**
     * 登录账号类型 client_id=[Admin后台管理, Admin_Slave 后台分店管理, back_admin 总端后台]
     */
    private String clientId;

    /**
     * 登录商家ID
     */
    private Long merchantId;

    /**
     * 登录门店ID
     */
    private Long storeId;

    public SecurityUser(){
    }

    public SecurityUser(UserDto  userDto){
        this.setId(userDto.getId());
        this.setUsername(userDto.getUser_name());
        this.setPassword(userDto.getPassword());
        this.setEnabled(userDto.getState());
        this.setClientId(userDto.getClient_id());
        this.setMerchantId(userDto.getMerchantId());
        this.setStoreId(userDto.getStoreId());
    }


    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @JsonIgnore
    @Override
    public String getPassword() {
        return this.password;
    }

    @JsonIgnore
    @Override
    public String getUsername() {
        return this.username;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return this.enabled;
    }
}
